#!/bin/bash

PKG_PATH=$(cd "$(dirname "$0")"; pwd)
ROOT_PATH=$PKG_PATH/../../
BIN_PATH=$ROOT_PATH/bin/
ROOTFS_PATH=$ROOT_PATH/rootfs/

echo "Current folder is $PKG_PATH"
if [ -z "$1" ]; then
	echo "Usage: $0 COMMAND(default: all)" 1>&2
	COMMAND="all"
else
	COMMAND="$1"
fi

. $BIN_PATH/source_cross_tool_chain_env.sh
export PATH=/opt/poky/2.0/imx6q/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/opt/qt5.8/bin/:$PATH

case $COMMAND in
c|config|configure)
	echo -e "\n----------Generate configuration----------"
	qmake
;; 

m|make|build)
	echo -e "\n---------- build ----------"
	make
;; 

i|install)
	# Install
	echo -e "\n----------Installing the binaries and libraries to $ROOTFS_PATH----------"
	#install -m 755 FaceRecognition $ROOTFS_PATH/usr/bin/
;; 

all)
	if $0 config; then
		if $0 build; then
			if $0 install; then
				echo "---------- build N install success !----------"
				exit 0
			fi
		fi
	fi
	
	echo "---------- build or install failed !----------"
	exit -1
	;;

clean)
	make clean
	;;

distclean)
	make distclean
	;;
*)
	echo "Usage: $0 COMMAND"
	exit 2
	;;
esac

